package com.hao.demo.zoo.client.config;

import com.alibaba.csp.sentinel.adapter.grpc.SentinelGrpcClientInterceptor;
import io.grpc.ClientInterceptor;
import lombok.extern.slf4j.Slf4j;
import net.devh.boot.grpc.client.interceptor.GlobalClientInterceptorConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

/**
 * @Description: TODO
 * @Author Hao
 * @Date 2021/6/8 14:47
 * @Version 2.0
 */
@Order(Ordered.LOWEST_PRECEDENCE)
@Configuration
@Slf4j
public class SentinelConfig {

    @Bean
    public ClientInterceptor sentinelGrpcClientInterceptor(){
        return new SentinelGrpcClientInterceptor();
    }

    @Bean
    public GlobalClientInterceptorConfigurer globalInterceptorConfigurerAdapter(ClientInterceptor sentinelGrpcClientInterceptor) {
        return registry -> registry.add(sentinelGrpcClientInterceptor);
    }

}
